package com.pwx.student.web.controller;


import com.pwx.student.common.ResponseResult;
import com.pwx.student.service.IRcStudentCourseService;
import com.pwx.student.utils.TokenUtils;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpRequest;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author saber
 * @since 2022-10-24
 */
@RestController
@RequestMapping("/rc-student-course")
public class RcStudentCourseController {

    @Autowired
    private IRcStudentCourseService irsc;

    @GetMapping("/showStudentCourse")
    public ResponseResult showStudentCourse(HttpServletRequest request){
        String authorization = request.getHeader("Authorization");

        Integer studentId =Integer.valueOf((String) TokenUtils.parseToken(authorization).get("jti"));

        return irsc.showStudentCourse(studentId);
    }

    @PostMapping("/changeCourse/{scId}")
    public ResponseResult changeCourse(@PathVariable("scId") Integer scId, HttpServletRequest request){
        String authorization = request.getHeader("Authorization");

        Integer studentId =Integer.valueOf((String) TokenUtils.parseToken(authorization).get("jti"));

        return irsc.changeCourse(scId,studentId);
    }

    @GetMapping("/studentCourseTime")
    public ResponseResult studentCourseTime(HttpServletRequest request){
        String authorization = request.getHeader("Authorization");

        Integer studentId =Integer.valueOf((String) TokenUtils.parseToken(authorization).get("jti"));

        return irsc.studentCourseTime(studentId);
    }

    @GetMapping("/studentScore")
    public ResponseResult studentScore(HttpServletRequest request){
        String authorization = request.getHeader("Authorization");

        Integer studentId =Integer.valueOf((String) TokenUtils.parseToken(authorization).get("jti"));

        return irsc.studentScore(studentId);
    }

}
